package org.opentcs.kcvehicle.communication.kc.udp.agv.param.function.write;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.opentcs.kcvehicle.communication.kc.common.byteutils.ByteUtils;

public class WriteValueMember {
  //变量成员偏移 2个字节
  private byte[] valueOffset;
  //变量成员长度 2个字节
  private byte[] valueLength;
  //变量成员值 4个字节
  private byte[] newValue;

  public WriteValueMember(Short valueOffset, Short valueLength, byte[] newValue) {
    this.valueOffset = ByteUtils.shortToBytes(valueOffset);
    this.valueLength = ByteUtils.shortToBytes(valueLength);
    this.newValue = newValue;
  }

  public byte[] toBytes() {
    ByteBuf byteBuf = Unpooled.buffer(8);
    byteBuf.writeBytes(valueOffset);
    byteBuf.writeBytes(valueLength);
    byteBuf.writeBytes(newValue);
    return byteBuf.array();
  }
}
